package com.sky.mapper;

import com.github.pagehelper.Page;
import com.sky.dto.GoodsSalesDTO;
import com.sky.dto.OrdersPageQueryDTO;
import com.sky.entity.Orders;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.time.LocalDateTime;
import java.util.List;

@Mapper
public interface OrderMapper {
	
	/**
	 * 根据id查询订单
	 *
	 * @param id
	 * @return
	 */
	@Select("select * from orders where id=#{id}")
	Orders getOrder(Long id);
	
	void submitOrder(Orders orders);
	
	@Select("select * from orders where number=#{number}")
	Orders getByNumber(String number);
	
	/**
	 * 修改订单信息
	 *
	 * @param orders
	 */
	void updateOrder(Orders orders);
	
	Page<Orders> getOrderList(OrdersPageQueryDTO ordersPageQueryDTO);
	
	/**
	 * 根据状态统计订单数量
	 *
	 * @param status
	 */
	@Select("select count(id) from orders where status = #{status}")
	Integer countStatus(Integer status);
	
	/**
	 * 超时订单
	 *
	 * @param status
	 * @param orderTime
	 * @return
	 */
	@Select("select * from orders where status = #{status} and order_time < #{orderTime}")
	List<Orders> overtimeOrders(Integer status, LocalDateTime orderTime);
	
	Integer countNumber(Integer status, LocalDateTime beginTime, LocalDateTime endTime);
	
	List<GoodsSalesDTO> getSalesTop10(LocalDateTime begin, LocalDateTime end);
	
	Double sumAmount(Integer status, LocalDateTime begin, LocalDateTime end);
}
